<template>
  <div class="ele-body">
    <!-- 表格 -->
    <div>
      <a-card :bordered="false">
        <ele-pro-table
          ref="table"
          row-key="scsctId"
          :datasource="datasource"
          :columns="columns"
          :where="where"
          :scroll="{ x: 'max-content' }"
        >
          <!-- table上边工具栏 -->
          <template #toolbar>
            <a-space>
              <a-button type="primary" @click="openEdit()">
                <template #icon>
                  <plus-outlined />
                </template>
                <span>新建喷淋规则配置模板</span>
              </a-button>
              <a-button type="primary" @click="setImageUploadSetting()">
                <template #icon>
                  <plus-outlined />
                </template>
                <span>设置图片上传方式</span>
              </a-button>

              <a-button type="primary" @click="setHeartbeat()">
                <template #icon>
                  <plus-outlined />
                </template>
                <span>批量设置心跳</span>
              </a-button>
              <a-button type="primary" @click="setDetectionConfig()">
                <template #icon>
                  <plus-outlined />
                </template>
                <span>批量设置检测配置</span>
              </a-button>
            </a-space>
          </template>

          <template #bodyCell="{ column, record }">
            <!-- table操作栏按钮 -->
            <template v-if="column.key === 'action'">
              <a-space>
                <a @click="openEdit(record)">修改</a>
                <a-divider type="vertical" />
                <a-popconfirm title="确定要删除此记录吗？" @confirm="remove(record)">
                  <a class="ele-text-danger">删除</a>
                </a-popconfirm>
                <a-divider type="vertical" />
                <a @click="distributeTemplate(record)">分发</a>
              </a-space>
            </template>
          </template>
        </ele-pro-table>
      </a-card>
    </div>
    <!-- 编辑弹窗 -->
    <DeviceSpraycameraSoftwareSprayruleTemplateEdit v-if="showEdit" v-model:visible="showEdit" :data="current" @done="reload" />
    <DeviceSpraycameraSoftwareSprayruleTemplateDistribute v-if="showDistribute" v-model:visible="showDistribute" :data="current" @done="reload" />
    <DeviceSpraycameraSoftwareImageUploadSettingDistribute v-if="showUploadImageSetting" v-model:visible="showUploadImageSetting" :data="current" @done="reload" />
    <DeviceSpraycameraSoftwareHeartbeatDistribute v-if="showHeartbeat" v-model:visible="showHeartbeat" :data="current" @done="reload" />
    <DeviceSpraycameraSoftwareDetectionConfigDistribute v-if="showDetectionConfig" v-model:visible="showDetectionConfig" :data="current" @done="reload" />
  </div>
</template>

<script>
import { PlusOutlined } from '@ant-design/icons-vue';
import { message } from 'ant-design-vue';
import DeviceSpraycameraSoftwareSprayruleTemplateEdit from './spraycamera-software-sprayrule-template-edit.vue';
import DeviceSpraycameraSoftwareSprayruleTemplateDistribute from './spraycamera-software-sprayrule-template-distribute.vue'
import {DeviceSprayCameraStaticConfigTemplateApi} from "@/api/property/spraycamera/DeviceSprayCameraStaticConfigTemplateApi";
import DeviceSpraycameraSoftwareImageUploadSettingDistribute from './spraycamera-software-imageuploadsetting-distribute.vue'
import DeviceSpraycameraSoftwareHeartbeatDistribute from './spraycamera-software-heartbeat-distribute.vue'
import DeviceSpraycameraSoftwareDetectionConfigDistribute from './spraycamera-software-detectionconfig-distribute.vue'
export default {
  name: 'DeviceSpraycameraSoftwareSprayruleTemplate',
  components: {
    PlusOutlined,
    DeviceSpraycameraSoftwareSprayruleTemplateEdit,
    DeviceSpraycameraSoftwareSprayruleTemplateDistribute,
    DeviceSpraycameraSoftwareImageUploadSettingDistribute,
    DeviceSpraycameraSoftwareHeartbeatDistribute,
    DeviceSpraycameraSoftwareDetectionConfigDistribute
  },
  async mounted() {
  },
  data() {
    return {
      // 表格列配置
      columns: [
        {
          title: '模板id',
          dataIndex: 'scsctId'
        },
        {
          title: '模板名称',
          dataIndex: 'templateName'
        },
        {
          title: '创建时间',
          dataIndex: 'createTime'
        },
        {
          title: '操作',
          key: 'action',
          width: 280,
          align: 'center'
        }
      ],
      // 表格搜索条件
      where: {},
      // 当前编辑数据
      current: null,
      // 是否显示编辑弹窗
      showEdit: false,
      showEdit1 : false,
      showDistribute : false,
      showUploadImageSetting : false,
      showHeartbeat : false,
      showDetectionConfig : false
    };
  },
  methods: {
    /**
     * 搜索按钮
     *
     * @author cancan
     * @date 2024/10/03 21:26
     */
    reload() {
      this.selection = [];
      this.$refs.table.reload({ page: 1 });
    },

    /**
     * 重置搜索
     *
     * @author cancan
     * @date 2024/10/03 21:26
     */
    reset() {
      this.where = {};
      this.$nextTick(() => {
        this.reload();
      });
    },

    /**
     * 删除
     *
     * @author cancan
     * @date 2024/10/03 21:26
     */
    async remove(row) {
      const result = await DeviceSprayCameraStaticConfigTemplateApi.delete({ scsctId: row.scsctId });
      message.success(result.message);
      this.reload();
    },

    /**
     * 打开新增或编辑弹窗
     *
     * @author cancan
     * @date 2024/10/03 21:26
     */
    openEdit(row) {
      this.current = row;
      this.showEdit = true;
    },

    distributeTemplate(row) {
      this.current = row;
      this.showDistribute = true;
    },
    setImageUploadSetting(row)
    {
      this.current = row;
      this.showUploadImageSetting = true;
    },
    setHeartbeat(row) {
      this.current = row;
      this.showHeartbeat = true;
    },
    setDetectionConfig(row) {
      this.current = row;
      this.showDetectionConfig = true;
    },
    /**
     * 获取表格数据
     *
     * @author fengshuonan
     * @date 2022/5/8 15:18
     */
    datasource({ page, limit, where, orders }) {
      return DeviceSprayCameraStaticConfigTemplateApi.findPage({ ...where, ...orders, pageNo: page, pageSize: limit });
    }
  }
};
</script>
